import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import org.jboss.resteasy.client.ClientRequest;
import org.jboss.resteasy.client.ClientResponse;
import br.com.news.utils.database.beans.PerfilBean;
import br.com.news.utils.database.beans.UsuarioBean;
import com.google.gson.Gson;



public class Teste {

	public static void main(String[] args) {

		try {

			UsuarioBean usuario = new UsuarioBean();
			usuario.setPerfil(new PerfilBean(1L));
			usuario.setLogin("paulo");
			usuario.setSenha("Senha");
			usuario.setStatus(true);
			usuario.setNome("Paulo");

			Gson gson = new Gson();
			String json = gson.toJson(usuario);

			ClientRequest request = new ClientRequest("http://localhost:8080/news-web-service-rest/Usuario/insert");
			request.accept("application/json");

			request.body("application/json", json);

			ClientResponse<String> response = request.post(String.class);

			if (response.getStatus() != 201) {
				throw new RuntimeException("Failed : HTTP error code : "
						+ response.getStatus());
			}

			BufferedReader br = new BufferedReader(new InputStreamReader(
					new ByteArrayInputStream(response.getEntity().getBytes())));

			String output;
			System.out.println("Output from Server .... \n");
			while ((output = br.readLine()) != null) {
				System.out.println(output);
			}

		} catch (MalformedURLException e) {

			e.printStackTrace();

		} catch (IOException e) {

			e.printStackTrace();

		} catch (Exception e) {

			e.printStackTrace();

		}

	}

}
